home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / A simple L229017162001.psc / frmSrc.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2002-01-06  |  8.7 KB  |  255 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSrc 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H8000000D&
  5.    BorderStyle     =   0  'None
  6.    Caption         =   "General Corporation"
  7.    ClientHeight    =   405
  8.    ClientLeft      =   5865
  9.    ClientTop       =   0
  10.    ClientWidth     =   1785
  11.    Icon            =   "frmSrc.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   405
  16.    ScaleWidth      =   1785
  17.    ShowInTaskbar   =   0   'False
  18.    Begin VB.Timer Timer2 
  19.       Interval        =   500
  20.       Left            =   2280
  21.       Top             =   2760
  22.    End
  23.    Begin VB.Timer Timer1 
  24.       Interval        =   700
  25.       Left            =   1440
  26.       Top             =   2760
  27.    End
  28.    Begin VB.CommandButton Command4 
  29.       Caption         =   "Command4"
  30.       Height          =   375
  31.       Left            =   240
  32.       TabIndex        =   4
  33.       Top             =   2280
  34.       Width           =   1095
  35.    End
  36.    Begin VB.CommandButton Command2 
  37.       Caption         =   "Command2"
  38.       Height          =   495
  39.       Left            =   1800
  40.       TabIndex        =   3
  41.       Top             =   1800
  42.       Width           =   975
  43.    End
  44.    Begin VB.PictureBox Picture1 
  45.       BackColor       =   &H00000000&
  46.       Height          =   1695
  47.       Left            =   -5880
  48.       ScaleHeight     =   1635
  49.       ScaleWidth      =   8835
  50.       TabIndex        =   2
  51.       Top             =   0
  52.       Width           =   8895
  53.       Begin VB.Label Label1 
  54.          AutoSize        =   -1  'True
  55.          BackStyle       =   0  'Transparent
  56.          Caption         =   "General Corporation"
  57.          BeginProperty Font 
  58.             Name            =   "MS Sans Serif"
  59.             Size            =   8.25
  60.             Charset         =   0
  61.             Weight          =   700
  62.             Underline       =   0   'False
  63.             Italic          =   0   'False
  64.             Strikethrough   =   0   'False
  65.          EndProperty
  66.          ForeColor       =   &H00000080&
  67.          Height          =   195
  68.          Left            =   5880
  69.          TabIndex        =   5
  70.          Top             =   120
  71.          Width           =   1710
  72.       End
  73.    End
  74.    Begin VB.CommandButton Command3 
  75.       Caption         =   "Command3"
  76.       Height          =   495
  77.       Left            =   960
  78.       TabIndex        =   1
  79.       Top             =   1800
  80.       Width           =   855
  81.    End
  82.    Begin VB.CommandButton Command1 
  83.       Caption         =   "Command1"
  84.       Height          =   495
  85.       Left            =   0
  86.       TabIndex        =   0
  87.       Top             =   1800
  88.       Width           =   855
  89.    End
  90. Attribute VB_Name = "frmSrc"
  91. Attribute VB_GlobalNameSpace = False
  92. Attribute VB_Creatable = False
  93. Attribute VB_PredeclaredId = True
  94. Attribute VB_Exposed = False
  95. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
  96. Const HWND_TOPMOST = -1
  97. Const SWP_SHOWWINDOW = &H40
  98. Private Type GUID
  99.     Data1 As Long
  100.     Data2 As Integer
  101.     Data3 As Integer
  102.     Data4(7) As Byte
  103.     End Type
  104. Private Const RASTERCAPS As Long = 38
  105. Private Const RC_PALETTE As Long = &H100
  106. Private Const SIZEPALETTE As Long = 104
  107. Private Type RECT
  108.     Left As Long
  109.     Top As Long
  110.     Right As Long
  111.     Bottom As Long
  112.     End Type
  113. Private Declare Function CreateCompatibleDC Lib "GDI32" ( _
  114.     ByVal hDC As Long) As Long
  115. Private Declare Function CreateCompatibleBitmap Lib "GDI32" ( _
  116.     ByVal hDC As Long, ByVal nWidth As Long, ByVal nHeight As Long _
  117.     ) As Long
  118. Private Declare Function GetDeviceCaps Lib "GDI32" (ByVal hDC As Long, _
  119.     ByVal iCapabilitiy As Long) As Long
  120. Private Declare Function SelectObject Lib "GDI32" (ByVal hDC As Long, _
  121.     ByVal hObject As Long) As Long
  122. Private Declare Function BitBlt Lib "GDI32" (ByVal hDCDest As Long, _
  123.     ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, _
  124.     ByVal nHeight As Long, ByVal hDCSrc As Long, ByVal XSrc As Long, _
  125.     ByVal YSrc As Long, ByVal dwRop As Long) As Long
  126. Private Declare Function DeleteDC Lib "GDI32" (ByVal hDC As Long) As Long
  127. Private Declare Function SelectPalette Lib "GDI32" (ByVal hDC As Long, _
  128.     ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
  129. Private Declare Function RealizePalette Lib "GDI32" ( _
  130.     ByVal hDC As Long) As Long
  131. Private Declare Function GetWindowDC Lib "user32" ( _
  132.     ByVal hwnd As Long) As Long
  133. Private Declare Function GetDC Lib "user32" ( _
  134.     ByVal hwnd As Long) As Long
  135. Private Declare Function GetWindowRect Lib "user32" ( _
  136.     ByVal hwnd As Long, lpRect As RECT) As Long
  137. Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, _
  138.     ByVal hDC As Long) As Long
  139. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  140. Private Type PicBmp
  141.     Size As Long
  142.     Type As Long
  143.     hBmp As Long
  144.     hPal As Long
  145.     Reserved As Long
  146. End Type
  147. Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" ( _
  148.     PicDesc As PicBmp, RefIID As GUID, _
  149.     ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
  150. Public Function CreateBitmapPicture(ByVal hBmp As Long, _
  151.     ByVal hPal As Long) As Picture
  152.     Dim r As Long
  153. Dim Pic As PicBmp
  154. ' IPicture requires a reference to "Stan
  155. '     dard OLE Types"
  156. Dim IPic As IPicture
  157. Dim IID_IDispatch As GUID
  158. ' Fill in with IDispatch Interface ID
  159. With IID_IDispatch
  160.     .Data1 = &H20400
  161.     .Data4(0) = &HC0
  162.     .Data4(7) = &H46
  163. End With
  164. With Pic
  165.     .Size = Len(Pic) ' Length of structure
  166.     .Type = vbPicTypeBitmap ' Type of Picture (bitmap)
  167.     .hBmp = hBmp ' Handle To bitmap
  168.     .hPal = hPal ' Handle To palette (may be null)
  169. End With
  170. ' Create Picture object
  171. r = OleCreatePictureIndirect(Pic, IID_IDispatch, 1, IPic)
  172. ' Return the new Picture object
  173. Set CreateBitmapPicture = IPic
  174. End Function
  175. Public Function CaptureWindow(ByVal hWndSrc As Long, _
  176.     ByVal Client As Boolean, ByVal LeftSrc As Long, _
  177.     ByVal TopSrc As Long, ByVal WidthSrc As Long, _
  178.     ByVal HeightSrc As Long) As Picture
  179.     Dim hDCMemory As Long
  180.     Dim hBmp As Long
  181.     Dim hBmpPrev As Long
  182.     Dim r As Long
  183.     Dim hDCSrc As Long
  184.     Dim hPal As Long
  185.     Dim hPalPrev As Long
  186.     Dim RasterCapsScrn As Long
  187.     Dim HasPaletteScrn As Long
  188.     Dim PaletteSizeScrn As Long
  189. ' Depending on the value of Client get t
  190. '     he proper device context
  191. If Client Then
  192.     hDCSrc = GetDC(hWndSrc) ' Get device context For client area
  193.     hDCSrc = GetWindowDC(hWndSrc) ' Get device context For entire window
  194. End If
  195. ' Create a memory device context for the
  196. '     copy process
  197. hDCMemory = CreateCompatibleDC(hDCSrc)
  198. ' Create a bitmap and place it in the me
  199. '     mory DC
  200. hBmp = CreateCompatibleBitmap(hDCSrc, WidthSrc, HeightSrc)
  201. hBmpPrev = SelectObject(hDCMemory, hBmp)
  202. ' Get screen properties
  203. RasterCapsScrn = GetDeviceCaps(hDCSrc, RASTERCAPS) ' Raster capabilities
  204. HasPaletteScrn = RasterCapsScrn And RC_PALETTE ' Palette support
  205. PaletteSizeScrn = GetDeviceCaps(hDCSrc, SIZEPALETTE) ' Size of palette
  206. ' If the screen has a palette make a cop
  207. '     y and realize it
  208.     hPalPrev = SelectPalette(hDCMemory, hPal, 0)
  209.     r = RealizePalette(hDCMemory)
  210. ' Copy the on-screen image into the memo
  211. '     ry DC
  212. r = BitBlt(hDCMemory, 0, 0, WidthSrc, HeightSrc, hDCSrc, _
  213. LeftSrc, TopSrc, vbSrcCopy)
  214. ' Remove the new copy of the the on-scre
  215. '     en image
  216. hBmp = SelectObject(hDCMemory, hBmpPrev)
  217. ' If the screen has a palette get back t
  218. '     he palette that was selected
  219. ' in previously
  220. If HasPaletteScrn And (PaletteSizeScrn = 256) Then
  221.     hPal = SelectPalette(hDCMemory, hPalPrev, 0)
  222. End If
  223. ' Release the device context resources b
  224. '     ack to the system
  225. r = DeleteDC(hDCMemory)
  226. r = ReleaseDC(hWndSrc, hDCSrc)
  227. ' Call CreateBitmapPicture to create a p
  228. '     icture object from the bitmap
  229. ' and palette handles. Then return the r
  230. '     esulting picture object.
  231. Set CaptureWindow = CreateBitmapPicture(hBmp, hPal)
  232. End Function
  233. Private Sub form_load()
  234. SetWindowPos Me.hwnd, HWND_TOPMOST, 400, 0, 0, 0, SWP_SHOWWINDOW
  235. Me.Width = 1785
  236. Me.Height = 405
  237. End Sub
  238. Private Sub Timer2_Timer()
  239. Me.Left = 5850
  240. Me.Height = 1
  241. Me.Width = 1
  242. Set Picture1.Picture = CaptureWindow(hWndScreen, False, 0, 0, _
  243.     Screen.Width \ Screen.TwipsPerPixelX, _
  244.     Screen.Height \ Screen.TwipsPerPixelY)
  245. frmSrc.Top = -35
  246. Me.Width = 1785
  247. Me.Height = 405
  248. End Sub
  249. Private Sub Timer1_Timer()
  250. Me.Width = 1785
  251. Me.Height = 405
  252. Me.Left = 17000
  253. Me.Top = 13000
  254. End Sub
  255.